class A_PERMUTE{ETP,ATP<$ARR{ETP}} |
---|
**** | Permutation algorithms - a bit bare right now. Usage:
_____src:_ARRAY{INT}_:=_|1,2,5|; _____p:_FLIST{INT}_:=_#(|2,1,0|); _____dest:_ARRAY{INT}_:=_#(3); _____i.e._first_element_of_"src"_s[0]=1_goes_to_dest[2] __________2nd_elt_of_src_(2)_goes_to_dest[1] __________3rd_elt_of_src_(5)_goes_to_dest[0] _____perm_alg:_A_PERMUTE{INT,ARRAY{INT}}; _____perm_alg.permute_into(src,p,dest); _____Should_permute_src_into_|5,2,1|; |
COMPARE{_} |
elt_eq(e1,e2:ETP):BOOL .. Included as elt_eq |
---|
**** | The "less than" relation used in the sorting routines. Compares the object "id" by default. May be redefined in descendants. |
elt_hash(e:ETP):INT .. Included as elt_hash |
---|
**** | A hash value associated with an element. Must have the property that if "elt_eq(e1,e2)" then "elt_hash(e1)=elt_hash(e2)". Can be defined to always return 0, but many routines will then become quadratic. Uses object "id" by default. May be redefined in descendants. |
elt_lt(e1,e2:ETP):BOOL .. Included as elt_lt |
---|
**** | The "less than" relation used in the sorting routines. Compares the object "id" by default. May be redefined in descendants. |
elt_nil: ETP .. Included as elt_nil |
---|
**** | Return the nil value. If the element is under $NIL then return e.nil. Otherwise, return void
_ |
is_elt_nil(e:ETP):BOOL .. Included as is_elt_nil |
---|
permute_into(src:ATP,new_pos:$ARR{INT},dest:ATP) |
---|
**** | Copy the entries from src into dest using the permutation array "new_positions" src[i] -> dest[new_pos[i]] Look at new_pos as a mapping from domain indices to range indices
_____src:_ARRAY{INT}_:=_|1,2,5|; _____p:_FLIST{INT}_:=_#(|2,1,0|); _____dest:_ARRAY{INT}_:=_#(3); _____i.e._first_element_of_"src"_s[0]=1_goes_to_dest[2] __________2nd_elt_of_src_(2)_goes_to_dest[1] __________3rd_elt_of_src_(5)_goes_to_dest[0] _____permute_into(src,p,dest);__--_____Destination=_|5,2,1|; |
shuffle(a:ATP) |
---|
**** | Shuffle the elements of self. This is a trivial, obvious implementation, but not sure if it is sufficient for good randomness |
sorted_is_permutation(p1,p2: ATP): BOOL |
---|
**** | Inputs must be sorted True if p1 is a permutation of p2. Requires self and p2 to both be pre-sorted |
to_reverse(a:ATP) |
---|
**** | Reverse the order of the elements in self. Self may be void. |
is_sorted(a: ATP): BOOL |
---|
valid_ind(dest: ATP,i: INT): BOOL |
---|